import pymysql
import time
import random
db= pymysql.connect(host="192.168.1.103",user="root",
 	password="00000000",db="pro",port=3306)
 
# 使用cursor()方法获取操作游标
cur = db.cursor()
time.sleep(3)
sql_update ="update orders set order_state = '%s' where id = %d"
 
cur = db.cursor()
for i in ['运输中', '已签收']:
    print(sql_update % (i,1))
    cur.execute(sql_update % (i,1))
    #提交
    db.commit()
    Temperatures_sql_update ="insert into temperatures (order_ID,temperature_new,is_delete) values (%d,%s,0)"
    #  insert into temperatures (order_ID,temperature_new) values (%d,%s)
    for j in range(100):
        if i == '运输中':
            temperature = random.randint(10,50)
            if temperature >= 30:
                cur.execute(sql_update % ('报警',1))
                alert = 1
                break
            cur.execute(Temperatures_sql_update % (1,temperature))
            db.commit()
            print(Temperatures_sql_update % (1,temperature))
    if alert:
        break
    time.sleep(3)
db.close()
